package com.edgarli.gamble.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import com.edgarli.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edgarli.gamble.mapper.TLottoHistoryMapper;
import com.edgarli.gamble.domain.TLottoHistory;
import com.edgarli.gamble.service.ITLottoHistoryService;

/**
 * 历史大乐透Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-14
 */
@Service
public class TLottoHistoryServiceImpl extends ServiceImpl<TLottoHistoryMapper, TLottoHistory> implements ITLottoHistoryService {
    @Autowired
    private TLottoHistoryMapper tLottoHistoryMapper;

    /**
     * 查询历史大乐透
     *
     * @param lottoHistoryId 历史大乐透主键
     * @return 历史大乐透
     */
    @Override
    public TLottoHistory selectTLottoHistoryByLottoHistoryId(Long lottoHistoryId) {
        return tLottoHistoryMapper.selectTLottoHistoryByLottoHistoryId(lottoHistoryId);
    }

    /**
     * 查询历史大乐透列表
     *
     * @param tLottoHistory 历史大乐透
     * @return 历史大乐透
     */
    @Override
    public List<TLottoHistory> selectTLottoHistoryList(TLottoHistory tLottoHistory) {
        return tLottoHistoryMapper.selectTLottoHistoryList(tLottoHistory);
    }

    /**
     * 批量删除历史大乐透
     *
     * @param lottoHistoryIds 需要删除的历史大乐透主键
     * @return 结果
     */
    @Override
    public int deleteTLottoHistoryByLottoHistoryIds(Long[] lottoHistoryIds) {
        return tLottoHistoryMapper.deleteTLottoHistoryByLottoHistoryIds(lottoHistoryIds);
    }

    /**
     * 删除历史大乐透信息
     *
     * @param lottoHistoryId 历史大乐透主键
     * @return 结果
     */
    @Override
    public int deleteTLottoHistoryByLottoHistoryId(Long lottoHistoryId) {
        return tLottoHistoryMapper.deleteTLottoHistoryByLottoHistoryId(lottoHistoryId);
    }

    @Override
    public void insertBatch(List<TLottoHistory> historyList) {
        for (TLottoHistory history : historyList) {
            if (!(tLottoHistoryMapper.selectCount(new LambdaQueryWrapper<TLottoHistory>().eq(TLottoHistory::getPeriods, history.getPeriods())) > 0)) {
                this.saveOrUpdate(history);
                //更新内置出现次数
            }

        }
    }
}
